import { useEffect, useState } from "react";
import axios from "axios"

export default function usePublishInfo(publishState){
  const user = JSON.parse(localStorage.getItem("token"));
  const [dataSource, setDataSource] = useState([]);

  useEffect(() => {
    const getRightList = async () => {
      try {
        const res = await axios.get(
          `http://localhost:3000/news?author=${user.username}&auditState=2&_expand=category&publishState=${publishState}`
        );
        setDataSource(res.data);
      } catch (error) {
        console.error("Failed to fetch data:", error);
      }
    };
    getRightList();
  }, [publishState]);

  return { dataSource, setDataSource};
}